package reflect;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class TestClassLoad {
    public static void main(String[] args) throws Exception {
        Class<?> clz = A.class;
        Object o = clz.newInstance();
        Method m = clz.getMethod("foo", String.class);
        for (int i = 0; i < 20; i++) {
            m.invoke(o, Integer.toString(i));
        }

        System.out.println(clz.getClassLoader());
        System.out.println(clz.getClassLoader().getParent());
        System.out.println(clz.getClassLoader().getParent().getParent());

        Object o1 = clz.getConstructor().newInstance();
        System.out.println(o1);
        Object o2 = clz.getConstructor(Boolean.class, Boolean.class).newInstance(false, true);
        System.out.println(o2);

        A a = new A();
        A b = (A) a.clone();
        System.out.println(JSONObject.toJSONString(a));
        System.out.println(b);
        a.setIsCheck(true);
        a.setSkill(true);
        String s = JSONObject.toJSON(a).toString();
        System.out.println(JSONObject.toJSONString(a));
        System.out.println(s);
        A t = JSONObject.parseObject(s, A.class);
        System.out.println(t.toString());

    }
}

class A implements Cloneable {

    @JSONField(name = "a")
    public boolean isCheck;
    @JSONField(name = "b")
    public boolean skill;

    public A() {

    }

    public A(Boolean isCheck, Boolean skill) {
        this.isCheck = isCheck;
        this.skill = skill;
    }

    public boolean getIsCheck() {
        return isCheck;
    }

    public void setIsCheck(boolean check) {
        isCheck = check;
    }

    public boolean isSkill() {
        return skill;
    }

    public void setSkill(boolean skill) {
        this.skill = skill;
    }

    public void foo(String name) {
        System.out.println("Hello, " + name);
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    @Override
    public String toString() {
        return "A{" +
                "isCheck=" + isCheck +
                ", skill=" + skill +
                '}';
    }
}